package com.hanggold.captcha.core.impl;

import com.hanggold.captcha.core.CaptchaAbstract;

import static com.hanggold.captcha.util.RandomUtil.randomInt;

/**
 * 通用验证码.
 *
 * @author <a href="mailto:free@hanggold.com">free</a>
 * @date 2021-09-30 13:47
 * @since 1.0.0
 **/
public class DefaultCaptcha extends CaptchaAbstract {
    
    private static final String DEFAULT_CHARACTER = "1QAZ2WSX3EDC4RFV5TGB6YHN7UJM8IK9OL0P2wsx1qaz4rfv5tgb6yhn7ujm8ik8ik9ol0p";
    
    @Override
    public final char[] alphas() {
        StringBuffer stringBuffer = new StringBuffer();
        char[] chars = DEFAULT_CHARACTER.toCharArray();
        int allChineseLen = chars.length;
        for (int i = 0; i < count(); i++) {
            stringBuffer.append(chars[randomInt(allChineseLen)]);
        }
        String value = stringBuffer.toString();
        return value.toCharArray();
    }
}
